package com.larno.larnosqliteexample.database.tables;

import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

/**
 * Created by sks on 2016/7/4.
 */
public class TodoTable {
    private static final String TAG = "TodoTable";

    public static final String TABLE_NAME = "todo";
    public static final String COLUMN_ID = "_id";
    public static final String COLUMN_CATEGORY = "category";
    public static final String COLUMN_SUMMARY = "summary";
    public static final String COLUMN_DESCRIPTION = "description";

    private static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + "("
            + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + COLUMN_CATEGORY + " TEXT NOT NULL, "
            + COLUMN_SUMMARY + " TEXT NOT NULL, "
            + COLUMN_DESCRIPTION + " TEXT NOT NULL"
            + ");";
    private static final String DRAOP_TABLE = "DROP TABLE IF EXISTS" + TABLE_NAME;

    public static void onCreate(SQLiteDatabase database) {
        database.execSQL(CREATE_TABLE);
    }

    public static void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
        Log.w(TAG, "Upgrading table from version " + oldVersion + " to " + newVersion + ", which will destroy all old data");
        database.execSQL(DRAOP_TABLE);
        onCreate(database);
    }
}
